package com.lyh.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lyh.common.annotation.Log;
import com.lyh.common.core.controller.BaseController;
import com.lyh.common.core.domain.AjaxResult;
import com.lyh.common.enums.BusinessType;
import com.lyh.system.domain.UserRebates;
import com.lyh.system.service.IUserRebatesService;
import com.lyh.common.utils.poi.ExcelUtil;
import com.lyh.common.core.page.TableDataInfo;

/**
 * 用户报单返佣Controller
 * 
 * @author ruoyi
 * @date 2023-06-01
 */
@RestController
@RequestMapping("/system/rebates")
public class UserRebatesController extends BaseController
{
    @Autowired
    private IUserRebatesService userRebatesService;

    /**
     * 查询用户报单返佣列表
     */
    @PreAuthorize("@ss.hasPermi('system:rebates:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserRebates userRebates)
    {
        startPage();
        List<UserRebates> list = userRebatesService.selectUserRebatesList(userRebates);
        return getDataTable(list);
    }

    /**
     * 导出用户报单返佣列表
     */
    @PreAuthorize("@ss.hasPermi('system:rebates:export')")
    @Log(title = "用户报单返佣", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserRebates userRebates)
    {
        List<UserRebates> list = userRebatesService.selectUserRebatesList(userRebates);
        ExcelUtil<UserRebates> util = new ExcelUtil<UserRebates>(UserRebates.class);
        util.exportExcel(response, list, "用户报单返佣数据");
    }

    /**
     * 获取用户报单返佣详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rebates:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userRebatesService.selectUserRebatesById(id));
    }

    /**
     * 新增用户报单返佣
     */
    @PreAuthorize("@ss.hasPermi('system:rebates:add')")
    @Log(title = "用户报单返佣", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserRebates userRebates)
    {
        return toAjax(userRebatesService.insertUserRebates(userRebates));
    }

    /**
     * 修改用户报单返佣
     */
    @PreAuthorize("@ss.hasPermi('system:rebates:edit')")
    @Log(title = "用户报单返佣", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserRebates userRebates)
    {
        return toAjax(userRebatesService.updateUserRebates(userRebates));
    }

    /**
     * 删除用户报单返佣
     */
    @PreAuthorize("@ss.hasPermi('system:rebates:remove')")
    @Log(title = "用户报单返佣", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userRebatesService.deleteUserRebatesByIds(ids));
    }
}
